import {getToken} from "@/utils/auth";

let ws = null;

export function createWebSocket() {
  if("WebSocket" in window){
    console.log("支持 WebSocket")
    if(getToken()){
      ws = new WebSocket("ws://localhost:20000/webSocket/1")

      ws.onmessage((evt) => {
        console.log(evt)
      })
    }
  } else {
    console.log("不支持支持 WebSocket")
  }
}

export function closeWebSocket() {
  if(ws != null){
    ws.close()
    console.log("关闭")
  }
}
